import {UserActions} from './user';

const initialState = [];

export const SearchResultActions = {
  SEARCH_RESULT_MAP_UPDATE: 'search_result_map_update',
  SEARCH_RESULT_MAP_RESET: 'search_result_map_reset',
};

export function updateSearchResultMap(payload) {
  return {
    type: SearchResultActions.SEARCH_RESULT_MAP_UPDATE,
    payload,
  };
}

export function resetSearchResultMap(payload) {
  return {
    type: SearchResultActions.SEARCH_RESULT_MAP_RESET,
    payload,
  };
}

export default function searchResultMap(state = initialState, action) {
  switch (action.type) {
    case SearchResultActions.SEARCH_RESULT_MAP_UPDATE:
      return [...action.payload];
    case SearchResultActions.SEARCH_RESULT_MAP_RESET:
      return initialState;
    case UserActions.USER_SIGN_OUT:
      return [];
    default:
      return state;
  }
}
